package com.jneagle.xlstool.bzwgjmx.view.handler;

import com.dwarfeng.subgrade.stack.handler.Handler;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;

import java.util.Locale;

/**
 * 国际化处理器。
 *
 * @author DwArFeng
 * @since 1.0.0
 */
@Component
public class I18nHandler implements Handler {

    private final ApplicationContext ctx;
    private final Locale locale;

    public I18nHandler(ApplicationContext ctx, @Qualifier("uiLocale") Locale locale) {
        this.ctx = ctx;
        this.locale = locale;
    }

    public String getMessage(String key) {
        return ctx.getMessage(key, null, locale);
    }

    public String getMessage(String key, Object[] args) {
        return ctx.getMessage(key, args, locale);
    }
}
